package com.ruoyi;

import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.SysConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;


/**
 * 启动程序
 *
 * @author ruoyi
 */

@Slf4j
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
public class RuoYiApplication implements CommandLineRunner {

    @Resource
    private RuoYiConfig ruoYiConfig;


    public static void main(String[] args) {
        try { // TODO 做好数据交付
            //  startEnv();
        } catch (Exception e) {
            e.printStackTrace();
        }
        initData();
        SpringApplication.run(RuoYiApplication.class, args);
    }

    // 项目交付需要打开
    //@SneakyThrows
    private static void startEnv() {
        log.info("=====>start environment.....");
        String nginx = "nginx.exe";
        //String mysql = "db\\bin\\mysqld.exe --no-defaults --port=50050 --wait_timeout=2147483 --interactive_timeout=2147483";
        //String redis = "redis\\redis-server.exe redis\\redis.windows.conf";
        List<String> list = Arrays.asList(nginx/*mysql*//*redis*/);
        for (String cmd : list) {
            log.info("=====>start: {}", cmd);
            try {
                Runtime.getRuntime().exec("cmd /c start /b " + cmd);
            } catch (Exception e) {
                log.error("nginx启动失败！");
            }
        }
    }


    /**
     * 初始化加载数据地址
     */
    private static void initData() {



    }


    @Override
    public void run(String... args) throws Exception {
        System.out.println("=====》 os name:" + System.getProperty("os.name"));
        String url = "http://127.0.0.1:8080/doc.html";
        String property = System.getProperty("os.name").toLowerCase();
        try {
            if (StringUtils.isNotBlank(property) && property.contains("windows")) {
                Runtime.getRuntime().exec("cmd /c start " + url);
            }
        } catch (Exception e) {
            log.error("前端页面启动失败！");
        }
    }


}
